package main

import (
	"commerce/api"
	"commerce/config"
	"commerce/inits"
	"commerce/interal/queue"
	"github.com/gin-gonic/gin"
	"log"
)

func main() {
	config.Init()
	inits.MysqlInit()
	inits.InitRabbitMq()
	go GetRabbit()

	router := gin.Default()
	api.Commerce(router)
	router.Run(":8181") // 监听并在 0.0.0.0:8080 上启动服务
}

func GetRabbit() {
	msgs := queue.QueueSub("QueueTest")

	forever := make(chan bool)
	//启用协程处理消息
	go func() {
		for d := range msgs {
			//消息逻辑处理，可以自行设计逻辑
			log.Printf("Received a message: %s", d.Body)

		}
	}()

	log.Printf(" [*] Waiting for messages. To exit press CTRL+C")
	<-forever
}
